Fix Python 3.12 deprecation warning about os.fork()#1070
Merged
mhucka merged 2 commits intoquantumlib:masterfrom Jun 5, 2025
Merged
Fix Python 3.12 deprecation warning about os.fork()#1070mhucka merged 2 commits intoquantumlib:masterfrom
mhucka merged 2 commits intoquantumlib:masterfrom
Conversation
I've adjusted the multiprocessing start method to 'forkserver' within the `ParallelLinearQubitOperator` class. This should resolve warnings concerning `os.fork()` in multithreaded environments (specifically with JAX in Python 3.12) that could potentially lead to deadlocks.
This change ensures that `multiprocessing.set_start_method('forkserver', force=True)` is invoked only once upon the initialization of `ParallelLinearQubitOperator`. The tests in `performance_benchmarks_test.py` are now passing without any warnings.
Collaborator
|
Seems like the default behaviour will change in python 3.14 (away from fork), maybe worth opening an issue and adding it as a link in the code to revisit in the future. |
fdmalone
approved these changes
Jun 5, 2025
mhucka
added a commit
to mhucka/OpenFermion
that referenced
this pull request
Sep 25, 2025
In Python 3.12, on Linux at least, `src/openfermion/testing/performance_benchmarks_test.py` produces the following warnings: ``` ~/.pyenv/versions/3.12.5/lib/python3.12/multiprocessing/popen_fork.py:66: RuntimeWarning: os.fork() was called. os.fork() is incompatible with multithreaded code, and JAX is multithreaded, so this will likely lead to a deadlock. self.pid = os.fork() src/openfermion/testing/performance_benchmarks_test.py::test_run_linear_qop src/openfermion/testing/performance_benchmarks_test.py::test_run_linear_qop src/openfermion/testing/performance_benchmarks_test.py::test_run_linear_qop src/openfermion/testing/performance_benchmarks_test.py::test_run_linear_qop src/openfermion/testing/performance_benchmarks_test.py::test_run_linear_qop ~/.pyenv/versions/3.12.5/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=3069778) is multi-threaded, use of fork() may lead to deadlocks in the child. self.pid = os.fork() ``` This can be resolved by calling `multiprocessing.set_start_method()` in `__init__` of the `ParallelLinearQuibitOperator` class. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Python 3.12, on Linux at least,
src/openfermion/testing/performance_benchmarks_test.pyproduces the following warnings:This can be resolved by calling
multiprocessing.set_start_method()in__init__of theParallelLinearQuibitOperatorclass.